package TP2;

public class Site {

	static final int stockInit = 6;
	static final int stockMax = 10;
	static final int borneSup = 8;
	static final int borneInf = 2;
	private int nbSites;
	private int nbVelos;

	public Site(int i) {
		this.nbSites = i;
	}

	public int getNbVelos() {
		return nbVelos;
	}

	public void setNbVelos(int NbVelos) {
		this.nbVelos = NbVelos;
	}

	public int getNbSites() {
		return nbSites;
	}

	public synchronized void emprunter() {
		while (nbVelos <= 0) {
			try {
				wait();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		nbVelos--;
	}

	public synchronized void deposer() {
		while (nbVelos == stockMax) {
			try {
				wait();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		nbVelos++;
	}

	public synchronized void retirer() {
		Camion.setStockVelos(Camion.getStockVelos() + (nbVelos - stockInit));
		nbVelos = stockInit;
	}

	public synchronized void ajouter() {
		Camion.setStockVelos(Camion.getStockVelos() - (stockInit - nbVelos));
		nbVelos = stockInit;
	}

}
